package com.lingnan.wanxiangxinxun.controller.admin;


import com.lingnan.wanxiangxinxun.entity.dto.query.NoticeDTO;
import com.lingnan.wanxiangxinxun.entity.po.Notice;
import com.lingnan.wanxiangxinxun.entity.vo.common.PageVO;
import com.lingnan.wanxiangxinxun.entity.vo.common.Result;
import com.lingnan.wanxiangxinxun.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 消息通知表 前端控制器
 * </p>
 *
 * @author swl
 * @since 2025-04-30
 */
@RestController
@RequestMapping("/admin/notice")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;

    //新增通知（全服通知）
    @PostMapping("/addGlobalNotice")
    public Result addGlobalNotice(@RequestBody Notice notice){
        if(notice.getType() != 1){
            return Result.error("通知类型参数错误");
        }else {
            return noticeService.addGlobalNotice(notice);
        }
    }


    //新增通知（针对某个用户）
    @PostMapping("/addPersonalNotice")
    public Result addPersonalNotice(@RequestBody Notice notice){
        if(notice.getType() != 2){
            return Result.error("通知类型参数错误");
        }else {
            return noticeService.addPersonalNotice(notice);
        }
    }



    // 分页查询全服通知
    @GetMapping("/getGlobalNotice")
    public Result getGlobalNotice(@RequestParam(defaultValue = "1")  long current, @RequestParam(defaultValue = "10")  long size){
        PageVO<Notice> noticeList = noticeService.getGlobalNotice(current,size);
        return Result.success(noticeList);
    }


    //条件查找消息
    @PostMapping("/getNoticeInCondition")
    public Result getNoticeInCondition(@RequestBody NoticeDTO noticeDTO){
        PageVO<Notice> vo = noticeService.getNoticeInCondition(noticeDTO);
        return Result.success(vo);
    }


}
